import App from './App'

// #ifndef VUE3
// import './composition-api'
import Vue from 'vue'
import cuCustom from './colorui/components/cu-custom.vue'
Vue.component('cu-custom', cuCustom)

import bxUtil from '@/common/util.js' // 公共方法(工具函数)
import bxBusinessFunction from '@/common/specific.js' // 通用业务函数
Vue.use(bxUtil) // 公共方法
Vue.use(bxBusinessFunction) // 通用业务函数



Vue.prototype.parseDate = function parseDate(date, time, type) {

  /** let date =newe Date();
   *   parseDate(date);
   *
   *      return {
   *         year:'2014-05-01',
   *          month:'05',
   *          day:'18',
   *          hours:12,
   *          minutes:06,
   *          seconds：10

   *
   *      }
   *   parseDate(date,{
   *          date:-5
   *      });
   *      返回当前时间减去5天的年月日
   *
   *
   *  parseDate(date,{
   *          month:-10
   *      });
   *
   *
   * parseDate(date,{
   *          year:-1
   *      });
   *
   *
   *  parseDate(date,{
   *          hours:-1
   *      });
   *
   *  返回当前时间减去上一年的的年月日
   *
   *
   *
   *
   */

  function getTime(nowDate2) {
    let year = nowDate2.getFullYear();
    let month = nowDate2.getMonth() + 1;
    let date = nowDate2.getDate();
    let hours = nowDate2.getHours();
    let minutes = nowDate2.getMinutes();

    let seconds = nowDate2.getSeconds();

    if (month < 10) {
      month = `0${month}`;
    } else {
      month = month.toString();
    }

    if (date < 10) {
      date = `0${date}`;
    } else {
      date = date.toString();
    }

    if (hours < 10) {
      hours = `0${hours}`;
    } else {
      hours = hours.toString();
    }

    if (minutes < 10) {
      minutes = `0${minutes}`;
    } else {
      minutes = minutes.toString();
    }

    if (seconds < 10) {
      seconds = `0${seconds}`;
    } else {
      seconds = seconds.toString();
    }

    return {
      instance: nowDate2,
      year: year,
      month: month,
      hours: hours,
      minutes: minutes,
      seconds: seconds,
      date: date,
      dateDate: `${year}-${month}-${date}`,
      datetime: `${year}-${month}-${date} ${hours}:${minutes}:${seconds}`,
      dateMonth: `${year}-${month}`
    };
  }

  if (!time) {
    return getTime(date);
  } else if (time.date) {
    if (typeof time.date == 'string') {
      time.date = parseInt(time.date);
    }
    date.setDate(date.getDate() + time.date);
    return getTime(date);
  } else if (time.month) {
    if (typeof time.date == 'string') {
      time.date = parseInt(time.date);
    }
    date.setMonth(date.getMonth() + time.month);
    return getTime(date);
  } else if (time.year) {
    if (typeof time.date == 'string') {
      time.date = parseInt(time.date);
    }
    date.setFullYear(date.getFullYear() + time.year);
    return getTime(date);
  } else if (time.hours) {
    if (typeof time.date == 'string') {
      time.date = parseInt(time.date);
    }
    date.setHours(date.getHours() + time.hours);

    return getTime(date);
  } else if (time.minutes) {
    if (typeof time.date == 'string') {
      time.date = parseInt(time.date);
    }
    date.setMinutes(date.getMinutes() + time.minutes);

    return getTime(date);
  }

}

// vuex
import store from './store'
Vue.prototype.$store = store


// Vue.prototype.parseDate= 

Vue.prototype.getUuid = function() {
  let time = new Date().getTime();

  let randomStr = 'abcdefghijklmnupqrstuvwxyz=-';

  let str = '';

  for (let i = 0; i < 10; i++) {
    let number = parseInt(Math.random() * randomStr.length);
    str = str + randomStr.charAt(number);
  }

  let timeStam = new Date().getTime();

  return `${timeStam}${str}`;
}


import uView from '@/uni_modules/uview-ui'
Vue.use(uView)
// uni.$u.config.unit = 'rpx'

Vue.config.productionTip = false
App.mpType = 'app'
const app = new Vue({
  store,
  ...App
})
app.$mount()
// #endif

// #ifdef VUE3
import {
  createSSRApp
} from 'vue'
export function createApp() {
  const app = createSSRApp(App)
  return {
    app
  }
}
// #endif
